package com.study.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version V1.0
 * @title: AppVersionTest
 * @description: ${DESCRIPTION}
 * @author: wanghuilong
 * @date: 2019-12-25 10:36
 * @copyright: http://fingo.com.my/
 */
public class AppVersionTest {

    static Integer version_row_id = 56;

    static String versionCode = "3.0.70";

    static Integer versionId = 1269;

    static String[] countrys = {"MY", "SG", "TH"};

    // ANDROID IOS
    static String[] drivers = {"IOS", "ANDROID"};

    // 是否强制更新 Optional:可选 Mandatory:强制
    static String updateType = "Optional";

    //appversion sql
    static String APPVERSION_INSTER_SQL = "INSERT INTO `t_app_version`(`id`,`country`, `app_name`, `version_code`, `version_id`, `client_type`, `update_type`, `version_status`) values";

    //appversionLang sql
    static String APPVERSION_LANG_INSTER_SQL = "INSERT INTO `t_app_version_lang`(`app_version_id`, `language`, `updete_desc`) values";

    //
    static String seporter = "\"";

    public static void main(String[] args) {
        Map<String, String> lang = new HashMap<>();
        lang.put("cn", "1、优化了“摇一摇”的游戏体验；\n" +
                "2、向您推荐了一些您可能感兴趣的商品；");
        lang.put("en", "1. Fingo Shake overall performance optimized\n" +
                "2. On the page, we recommend products that you may be interested");
        lang.put("ms", "1. Prestasi keseluruhan Fingo Shake dioptimumkan\n" +
                "2. Pada halaman kami mengesyorkan produk yang mungkin anda minati\n");
        lang.put("th", "1.เพิ่มประสิทธิภาพของเกมส์ \"fingo shake\" ให้สนุกมากยิ่งขึ้น\n" +
                "2.แนะนำผลิตภัณฑ์ที่คุณสนใจ");
        List<String> sql = new ArrayList();
        for (int i = 0; i < countrys.length; i++) {
            String country = countrys[i];
            for (int j = 0; j < drivers.length; j++) {
                int version_data_id = version_row_id++;
                String driver = drivers[j];
                String sql1 = createAppVersionSql(version_data_id, country, driver);
                System.out.println(sql1);
                sql.add(sql1);
                for (Map.Entry<String, String> entry : lang.entrySet()) {
                    String sql2 = createAppVersionLangSql(version_data_id, entry.getKey(), entry.getValue());
                    System.out.println(sql2);
                    sql.add(sql2);
                }
            }
        }
        System.out.println(version_row_id);
        FileUtil.writeToFileByLine(sql, "/Users/fingo/IdeaProjects/lazy/src/main/resources/file/1.txt");
    }

    private static String createAppVersionLangSql(int version_data_id, String language, String text) {
        StringBuilder stringBuilder = new StringBuilder(APPVERSION_LANG_INSTER_SQL);
        stringBuilder.append("(");
        setValue(stringBuilder, version_data_id, null, null);
        setValue(stringBuilder, language, seporter, ",");
        setValue(stringBuilder, text, seporter, ",");
        stringBuilder.append(")");
        return stringBuilder.append(";").toString();
    }

    public static String createAppVersionSql(Integer id, String country, String driver) {
        StringBuilder stringBuilder = new StringBuilder(APPVERSION_INSTER_SQL);
        stringBuilder.append("(");
        setValue(stringBuilder, id, null, null);
        setValue(stringBuilder, country, seporter, ",");
        setValue(stringBuilder, "fingo", seporter, ",");
        setValue(stringBuilder, versionCode, seporter, ",");
        setValue(stringBuilder, versionId, null, ",");
        setValue(stringBuilder, driver, seporter, ",");
        setValue(stringBuilder, updateType, seporter, ",");
        setValue(stringBuilder, "released", seporter, ",");
        stringBuilder.append(")");
        return stringBuilder.append(";").toString();
    }

    public static void setValue(StringBuilder stringBuilder, Object value, String seporter, String start) {
        if (null != start) {
            stringBuilder.append(start);
        }
        if (null != seporter) {
            stringBuilder.append(seporter);
        }
        stringBuilder.append(value);
        if (null != seporter) {
            stringBuilder.append(seporter);
        }
    }
}
